home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / INFO / PCCDEMO.ZIP / COMP1.EXE / ASSEMBLY.PRS < prev    next >
Text File  |  1993-12-20  |  9KB  |  140 lines

  1.                              ÇÆÆäîüïÿ ïÇìåöÇåä àÄæ ÅæÄåæÇîîäæÆ ╬╠╧╧╬╠╬╠╬╠╬╠╡
  2.                                    
  3.                                    │        ∩α±≤ ¢:  ≤ τ Σ   Γ ∩ ⌠
  4.                                    │
  5.                        ▄   ▄       │     In this   first article I will
  6.  ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄▄▄ █▄▄ █ ▄ ▄   │  attempt  to  introduce  the basic
  7.  ▄▄█ █▄▄ █▄▄ █▄█ █ █ █ █ █ █ █ █   │  concepts  of   assembly  language
  8.  █▄█ ▄▄█ ▄▄█ █▄▄ █ █ █ █▄█ █ █▄█   │  programming.  If   you   have  no
  9.                              ▄▄█   │  knowledge  of  assembly language,
  10. σ ε ±   ∩ ± ε µ ± α ∞ ∞ Σ ± ≥      │  you    may  find    this  article
  11.                                    │  fairly  heavy-going,  but  if you
  12.                                    │  stick  with   it,  things  should
  13.                                    │  become easier later on.
  14.            ß√ ≤εß√ µ±α√            │
  15.                                    │     Since  assembly   language  is
  16.    ≤τΦ≥ ≥Σ±ΦΣ≥   εσ  α±≤ΦΓδΣ≥  Φ≥  │  really  a   CPU-level programming
  17. αΦ∞Σπ  ∞αΦφδ√  α≤   Γ  αφπ ∩α≥Γαδ  │  language,   it seems   logical to
  18. ∩±εµ±α∞∞Σ±≥   ÷τε ÷αφ≤   ≤ε δΣα±φ  │  begin with  a quick    tour    of
  19. τε÷   ≤ε   ∩±εµ±α∞   Φφ  α≥≥Σ∞ßδ√  │  the    CPU  itself.   The  lowest
  20. δαφµ⌠αµΣ.                          │  common denominator of   the Intel
  21.                                    │  80x86 family  of  processors used
  22.                                    │  in all    IBM-compatible machines
  23.                                 
  24.  
  25. is the  8086,  so that is the CPU  │  more    quickly    than    memory
  26. we  will  be  looking  at.         │  which  is outside the CPU.
  27.    Note  that  all  the following  │
  28. information    applies  to    all  │     2. The   execution  unit. This
  29. 80x86  processors  when they  are  │  is  the  part  of  the  CPU which
  30. running  in real  mode. DOS  runs  │  actually   performs computations.
  31. in    real  mode,  so    programs  │  The     registers  are  contained
  32. written   to    run   under   DOS  │  inside the execution unit.
  33. will   be  running  in  real mode  │
  34. too.                               │     3. The    bus  interface unit.
  35.                                    │  The  CPU  is   connected  to  the
  36.    From the    programmer's point  │  outside world via  this unit. All
  37. of view,   the  CPU can  be split  │  data  entering  and  leaving  the
  38. into  three   logical   units  as  │  CPU travels   through   the   bus
  39. follows:                           │  interface unit.
  40.                                    │     Of course,  the CPU  is a  far
  41.    1.   The    registers.   These  │  more  complex  piece  of hardware
  42. are   storage    locations inside  │  than    this  simple    breakdown
  43. the    CPU,  analogous    to RAM.  │  might    suggest,   but  for  the
  44. Registers can   be accessed  much  │  purpose of  this article  we only
  45.  
  46.  
  47. need to  worry  about the   above  │  looking at these registers here.
  48. three  units.  I will now discuss  │
  49. each of  the three  units in more  │     On an 8086,  all registers are
  50. detail.                            │  16  bits  wide.  This  means that
  51.                                    │  they  can  hold  unsigned  values
  52.                                    │  from 0 to 65,535 (0 to FFFF hex),
  53.   ôçä  æäåêÆôäæÆ                   │  or signed values  from -32,768 to
  54.                                    │  32,767 (8000 to 7FFF   hex).  The
  55.    The 8086  register set  can be  │  upper  and   lower   8   bits  of
  56. sub-divided  into  three classes:  │  some registers  can   be accessed
  57. general     registers,    segment  │  separately.  Each    8-bit  "sub-
  58. registers, and  status registers.  │  register" can   hold  an unsigned
  59. These      three   classes     of  │  value from 0 to 255 (0 to FF hex)
  60. registers   make   up   the  base  │  or a  signed value  from -128  to
  61. register    set  common    to all  │  127  (80  to 7F hex).  The  80386
  62. 80x86  processors.      The  more  │  (and  its  successors)  have some
  63. complex CPUs also have protection  │  32-bit registers, but   these are
  64. registers,   control   registers,  │  usually just   used   as   16-bit
  65. test    registers    and    debug  │  registers when running under DOS.
  66. registers,  but  I  will  not  be  │
  67.  
  68.  
  69.  ≤τΣ µΣφΣ±αδ ±ΣµΦ≥≤Σ±≥             │  on.   Some    of    the   general
  70.                                    │  registers,      particularly  SP,
  71.    In some    ways, the   general  │  have  special   uses which I will
  72. registers     are  similar     to  │  discuss later.
  73. variables    in        high-level  │
  74. languages.   Like variables, they  │    ≤τΣ ≥Σµ∞Σφ≤ ±ΣµΦ≥≤Σ±≥
  75. are used   to  store   data while  │
  76. the program  is  working  on that  │     Whenever you  need to  address
  77. data.    Unlike  variables,   the  │  memory  on  an 8086, you actually
  78. size   and   number    of general  │  use   two   addresses.   This  is
  79. registers   is  strictly limited.  │  because the execution  unit  only
  80. The basic  general  registers are  │  works   with   16   bit  numbers,
  81. known as  AX, BX,  CX, DX, SI, DI  │  while   memory addresses  are  20
  82. , SP and BP. It   is possible  to  │  bits  wide,  allowing   up  to  1
  83. access the first four (AX, BX, CX  │  megabyte  of   memory   to     be
  84. and  DX)  in  two  separate 8-bit  │  accessed    by   the  CPU  (later
  85. alves. The upper 8 bits of AX are  │  processors have  even more   bits
  86. collectively known    as  AH, and  │  in   their  addresses,   allowing
  87. the low  8 bits  are  AL. BX   is  │  access   to  more  memory).   The
  88. split   into BH   and  BL, and so  │  first    address,   called    the
  89.  
  90.  
  91. offset,   is   specified   in   a  │  the   instruction  pointer,   IP.
  92. general   register  or   directly  │  This  register,  along  with  the
  93. ("immediately")    in         the  │  segment   register   called   CS,
  94. instruction  which  is  accessing  │  always   points   at   the   next
  95. memory.   The   second   address,  │  instruction to be   executed, and
  96. the     segment,     is    always  │  is used to fetch each instruction
  97. specified   by     the   contents  │  in turn from   memory so  that it
  98. of    one    of    the    segment  │  can be executed. The other status
  99. registers. You   may be wondering  │  register  is called  FLAGS.
  100. how two 16-bit registers can make  │     Every  time  the  CPU performs
  101. a 20-bit address, but you'll have  │  an  arithmetic operation, some of
  102. to wait  until  I  get  around to  │  the bits in FLAGS are updated  to
  103. taking a  closer  look  at memory  │  reflect  the    outcome  of   the
  104. addressing for the answer.         │  operation. Some of the flags are:
  105.                                    │  CF,  the     carry   flag,  which
  106.   ≤τΣ ≥≤α≤⌠≥ ±ΣµΦ≥≤Σ±≥             │  indicates  (among  other  things)
  107.                                    │  that    the    result    of    an
  108.    There are  only two  registers  │  addition/subtraction    was   too
  109. in  this  class, so  I'll look at  │  big/small to fit  into the number
  110. each  one    separately. Firstly,  │  of bits allocated for it; PF, the
  111.  
  112.  
  113. parity flag, which  is   set to 1  │  retrieved  from   memory  or  I/O
  114. whenever the result an arithmetic  │  (input/output) ports.
  115. operation has  an even  number of  │
  116. bits set to 1; ZF, the zero flag,  │
  117. which is set  to one whenever the  │   ôçä üöÆ êìôäæàÇéä öìêô
  118. result of an arithmetic operation  │
  119. is zero.                           │     This unit  connects the CPU to
  120.                                    │  all  external  devices, including
  121.                                    │  memory.  Whenever  an instruction
  122. ôçä äùäéöôêÄì öìêô                 │  needs data from memory or  an I/O
  123.                                    │  port,  it  is  the  BIU  that  is
  124.    The execution    unit contains  │  responsible  for  fetching   that
  125. the entire register  set, as well  │  data. Similarly, the  BIU handles
  126. as   the   arithmetic/logic  unit  │  all outgoing data from the CPU to
  127. (ALU). This   unit  performs  all  │  memory or I/O ports.
  128. computations     necessary     to  │
  129. complete   all  instructions. The  │
  130. execution unit  communicates with  │     Well, that completes our brief
  131. the bus interface   unit whenever  │  tour  of  the  CPU.  In  the next
  132. data  needs  to  be  sent  to  or  │  article,   I will   introduce the
  133.  
  134.  
  135. basic  structure   of   a  simple  │
  136. assembly language  program,   and  │
  137. discuss    the    procedure   for  │
  138. creating an executable file  from  │
  139. your source code ñ                 │
  140.